import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;


public class FirstTest {

	public static void main(String[] args) {
		
		Options opt = new Options();
		opt.addOption("p", false, "no error if existing,make parent directories as needed");
		opt.addOption("v", false, "explain what is being done");
		
		opt.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("search for builfile"
				+ "the root of the filesystem and user it").create("O"));
		
		opt.addOption(OptionBuilder.withLongOpt("block-size").
				withDescription("use SIZE-byte blocks").withValueSeparator('=').hasArg().create());
		
		opt.addOption("h", "help", false, "print help for the command");
		
		String formatStr = "gmkdir [-p][-v/--verbose][--block-size][-h/--help] DirecotryName";
		
		HelpFormatter format = new HelpFormatter();
		CommandLineParser parse = new PosixParser();
		CommandLine cli = null;
		try {
			cli = parse.parse(opt, args);
		} catch (ParseException e) {
			
			format.printHelp(formatStr, opt);
		}
		
		if(cli.hasOption("h")){
			
			HelpFormatter hf = new HelpFormatter();
			hf.printHelp(formatStr, "", opt, "");
			return;
		}
		if(cli.hasOption("p")){
			
			System.out.println("has p");
		}
		if(cli.hasOption("v")){
			
			System.out.println("has v");
		}
		if(cli.hasOption("block-size")){
			
			System.out.println("block-size=" + cli.getOptionValue("block-size"));
		}
		
		String[] str = cli.getArgs();
		int length = str.length;
		System.out.println("length=" + length);
	}
}
